<!DOCTYPE html>
<html lang="cn">

<head>
	<meta charset="UTF-8">
	<title>PtjHtml</title>
</head>

<body>
	<h1>"A test for converting proto to json.</h1>
	<textarea style="height: 200px; width:300px;" id="TxtRespond"></textarea>
</body>
<script src="js/PkgUser.js"></script>
<script type="text/javascript">
	var oRpd = new proto.PkgUser.PhtList_Respond(); // proto.PkgUser.PhtList_Respond
	oRpd.setCode(0x3001);
	oRpd.setCommand("Usr_Pht_List");
	oRpd.setResult("0");
	oRpd.setMessage("成功");
	var oItm = oRpd.addList(); // proto.PkgUser.PhtList_Item
	oItm.setPhtIdntifr("1");
	oItm.setPhtStatus("1");
	oItm.setUrlFinalztion("https://www.baidu.com/1.jpg");
	oItm = oRpd.addList(); // proto.PkgUser.PhtList_Item
	oItm.setPhtIdntifr("2");
	oItm.setPhtStatus("1");
	oItm.setUrlFinalztion("https://www.baidu.com/2.jpg");
	var jDat = oRpd.toObject();
	console.log("PhtList_Respond is: " + JSON.stringify(jDat));

	var aBfr = oRpd.serializeBinary(); // Uint8Array
	var oPkg = proto.PkgUser.MsgCommon_Respond.deserializeBinary(aBfr.slice(0, 5));
	var nCde = oPkg.getCode();

	switch (nCde) {
		case 0x3001: {
			oRpd = proto.PkgUser.PhtList_Respond.deserializeBinary(aBfr);
			jDat = oRpd.toObject();
		}
		break;
		default: {
			jDat = {};
		}
		break;
	}

	document.getElementById("TxtRespond").value = JSON.stringify(jDat);
</script>

</html>